document.body.style.margin = "0"
//side style
document.getElementById('side').style.float = 'left'
document.getElementById('side').style.height = window.innerHeight+"px"
document.getElementById('side').style.width = "11vw"
document.getElementById('side').style.backgroundColor = '#252a2f'

//side html
document.getElementById('side').innerHTML = 
"<div style='margin-top:3vh;margin-right:1vw;color:#fff;font-size:0.9vw;margin-left:1vw;font-weight:bold'><img src='../../public/img/set.png' style='margin-right:vw;margin-top:0.5vh;width:1vw'><span style='position:relative;left:1vw;top:-0.2vh'>易代付</span></div>"
document.getElementById('side').innerHTML += "<div id='showall' style='margin-top:1.3vh'>"
document.getElementById('side').innerHTML += "</div>"
document.getElementById('side').style.font = ""
//side showall
var form = {}
form.token = sessionStorage.getItem('token')
console.log(form.token)
$.ajax({
    url:initObj.url + "/api/role/selectAuthority",
    // data:JSON.stringify(form),
    datatype:'json',
    type:'get',
    beforeSend: function(request) {
       request.setRequestHeader("token", form.token);
    },
    success:function(res){
        res = $.parseJSON(res.data.panelPermissions)
        console.log(res)
            for(var key in res){
                for(var v in res[key]){
                    if(v === dangqian){
                        document.getElementById('showall').innerHTML += 
                    "<div onclick='turn("+v+")' style='height:6vh;color:#fff' class='dangqian'><img src='../../public/img/"+v+".png' style='margin:1.5vh 0.5vw 0 1vw'><span style='display:block;margin-top:-3vh;margin-left:3vw'>"+res[key][v]+"</span></div>"
                    }else{
                        document.getElementById('showall').innerHTML += 
                    "<div onclick='turn("+v+")' style='height:6vh;color:#fff'><img src='../../public/img/"+v+".png' style='margin:1.5vh 0.5vw 0 1vw'><span style='display:block;margin-top:-3vh;margin-left:3vw'>"+res[key][v]+"</span></div>"
                    }    
                }
            }   
        document.getElementsByClassName('dangqian')[0].style.backgroundColor = '#666'
    }
})

function turn(id){
    switch(id){
        case 1:
        window.location.href = "../shouye/shouye.html";
        break;
        case 2:
        window.location.href = "../daifu/daifu.html";
        break;
        case 3:
        window.location.href = "../zhuanzhangrecord/zhuanzhangrecord.html";
        break;
        case 4:
        window.location.href = "../message/message.html";
        break;
        case 5:
        window.location.href = "../safe/safe.html";
        break;
        case 6:
        window.location.href = "../shouye-admin/shouye-admin.html";
        break;
        case 7:
        window.location.href = "../chongzhiguanli/chongzhiguanli.html";
        break;
        case 8:
        window.location.href = "../daifuguanli/daifuguanli.html";
        break;
        case 9:
        window.location.href = "../huzhuanguanli/huzhuanguanli.html";
        break;
        case 10:
        window.location.href = "../message-admin/message-admin.html";
        break;
        case 11:
        window.location.href = "../bankguanli/bankguanli.html";
    }
}

//inner top style
document.getElementById('inner').style.marginLeft = "11vw"
document.getElementById('inner').style.width = "89vw"
document.getElementById('top').style.height = "7vh"
// document.getElementById('top').style.backgroundImage = "url(../../public/img/bgtop.png)"
document.getElementById('top').style.backgroundColor = "#252a2f"
document.getElementById('top').style.fontSize = "14px"

//top showall
$.ajax({
    url:initObj.url + "/api/user/selectUser",
    // data:JSON.stringify(form),
    datatype:'json',
    type:'get',
    beforeSend: function(request) {
       request.setRequestHeader("token", form.token);
    },
    success:function(res){
        sessionStorage.setItem('contacts',res.data[0].contacts)
        // console.log(sessionStorage.getItem("contacts"))
        document.getElementById('top').innerHTML = 
"<div style='float:right;color:#fff;margin-top:3vh;margin-right:7vw'>您好， <span style='color:#00c3c8'>"+sessionStorage.getItem("contacts")+"</span><button style='background-color:transparent;border:0;margin-left:3vw;color:#fff;font-size:14px' onclick='update_password()'>修改密码</button><span style='margin:0 0.3vw'>|</span><button onclick='go_back()' style='background-color:transparent;border:0;color:#fff;font-size:14px'>安全退出</button></div>"
    }
})

function update_password(){
    window.location.href = "../safe/safe.html";
}
function go_back(){
    sessionStorage.setItem('token',"")
    window.location.href = "../../index.html"
}